﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Keepo.Models;

namespace AlbumDesigner.Models.Types
{
    public class ImageCategoryData
    {
        public int CategoryId { get; set; }
        public string Title { get; set; }
        public bool Deletable { get; set; }
        public int ItemsCount { get; set; }

        public ImageCategoryData(ImageCategory category)
        {
            this.CategoryId = category.ImageCategoryId;
            this.Title = category.TitleHebrew;
            this.Deletable = category.Deletable;

            using (AlbumContext db = new AlbumContext())
            {
                this.ItemsCount = db.BackgroundImages.Where(m => m.ImageCategoryId == category.ImageCategoryId && m.IsRemoved == false).Count();
            }
        }

        public ImageCategoryData(VectorCategory category)
        {
            this.CategoryId = category.VectorCategoryId;
            this.Title = category.TitleHebrew;
            this.Deletable = true;

            using (AlbumContext db = new AlbumContext())
            {
                this.ItemsCount = db.DesignVectors.Where(m => m.VectorCategoryId == category.VectorCategoryId && m.IsRemoved == false).Count();
            }
        }

        public ImageCategoryData(LayoutCategory category)
        {
            this.CategoryId = category.LayoutCategoryId;
            this.Title = category.TitleHebrew;
            this.Deletable = category.Deletable;

            using (AlbumContext db = new AlbumContext())
            {
                this.ItemsCount = db.PageLayouts.Where(m => m.LayoutCategoryId == category.LayoutCategoryId && m.IsRemoved == false).Count();
            }
        }

        public ImageCategoryData(PremadePageCategory category)
        {
            this.CategoryId = category.PremadePageCategoryId;
            this.Title = category.TitleHebrew;
            this.Deletable = category.Deletable;

            using (AlbumContext db = new AlbumContext())
            {
                this.ItemsCount = db.PremadePages.Where(m => m.PremadePageCategoryId == category.PremadePageCategoryId).Count();
            }
        }
    }
}